#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "dialog.h"

#include <QDialog>
#include <QDebug>
#include <QAction>
#include <QString>
#include <QKeySequence>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{

    this->setWindowTitle("窗口传值测试");
    ui->setupUi(this);

    openAction = new QAction("open", this);
    openAction->setShortcuts(QKeySequence::Open);
    openAction->setStatusTip(tr("Open an existing file"));
    connect(openAction, &QAction::triggered, this, &MainWindow::open);

    QToolBar *toolBar2 = addToolBar(tr("&File2"));
    toolBar2->addAction(openAction);


    textEdit = new QWidget();

}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::receiveData(QString val)
{
    QString str = QString("%1").arg(val);
    qDebug() << str;

    ui->textEdit->setText(str);
}

void MainWindow::open()
{

    Dialog *dlg = new Dialog;
    //关联信号和槽函数
    connect(dlg, SIGNAL(sendData(QString)), this, SLOT(receiveData(QString)));
    dlg->show();
}



